function groupDeal(json) {
    var dataMap = {};
    var min = 2;
    var max = 4;
    var json = eval("(" + json + ")");
    var groupHtml = "";
    for (var key in json) {
        var data = json[key];//[]
        var title = "C00" + key;
        switch (key) {
            case "0" :
                title = "C001";
                break;
            case "1" :
                title = "C002";
                break;
            case "2" :
                title = "C003";
                break;
            case "3" :
                title = "C005";
                break;
            case "4" :
                title = "C006";
                break;

        }
        data = data.substring(1, data.length - 1).replaceAll("\"", "");
        //留下做对比
        // var tmp = data.replaceAll("庄", "<span style='color:red'>庄</span>");

        dataMap[title] = data;
        var arr = data.split(',');
        var htmtmp = "<div style='display:inline-block;border:1px solid black;'><h5>" + title + "</h5>";
        //分组
        for (var i = min; i < max; i++) {
            //获得已分组列表
            var groupDataListSize = insertData(arr, i);
            //分组列表在页面显示
            htmtmp += getListHtml(groupDataListSize, i, "庄");
        }
        htmtmp = htmtmp + "</div>";
        groupHtml += htmtmp;
    }

    //$('#C001').html(compare);
    return groupHtml;
}

function insertData(list, size) {
    var groupDataList = [];
    for (var i = 0; i < list.length; i++) {
        var data = list[i];
        if (i == 0) {
            var groupData = new GroupData(size);
            groupData.insertData(data);
            groupDataList.push(groupData);
        } else {
            var groupData = groupDataList[groupDataList.length - 1];
            if (groupData.arr.length == groupData.size) {
                var groupDataNew = new GroupData(size);
                groupDataNew.insertData(data);
                groupDataList.push(groupDataNew);
            } else {
                groupData.insertData(data);
            }
        }
    }
    return groupDataList;
}

function GroupData(size) {
    this.size = size;
    this.arr = new Array(1);
    this.getSize = function () {
        return this.size;
    };
    this.insertData = function (data) {
        var nowLength = this.arr.length;
        if (nowLength == this.size) {
            var newGroupData = new GroupData(this.size);
            newGroupData = newGroupData.insertData(data);
            return newGroupData;
        }
        if (null == this.arr[0]) {
            this.arr[0] = data;
            return this;
        }
        this.arr.push(data);
        return this;
    };
    this.getIndexHtml = function (index) {
        var stringBuffer = "";
        if (index >= this.arr.length) {
            return stringBuffer;
        }
        if (this.arr[index] == "庄") {
            stringBuffer += "<span style='color:red'>" + this.arr[index] + "</span>";
        } else {
            stringBuffer += this.arr[index];
        }
        return stringBuffer;
    }
}

function getListHtml(groupDataList, size, test) {
    var stringBuffer = "<table>";
    //每一行显示·过去
    for (var j = 0; j < size; j++) {
        var stringBufferLine = "<tr>";
        for (var i = 0; i < groupDataList.length; i++) {
            var groupData = groupDataList[i];
            stringBufferLine += "<td>" + groupData.getIndexHtml(j) + "</td>";
        }
        stringBufferLine += "</tr>";
        stringBuffer += stringBufferLine;
    }
    stringBuffer += testResult(groupDataList, size);
    //最后添加一个判断 全中是或者否

    return stringBuffer + "</table><br/>";
}

//
function testResult(groupDataList, size) {
    var diff = $('#diff').prop("checked");
    var same = $('#same').prop("checked");
    if (diff) {
    }
    if (same) {
    }
    var stringBufferLine = "<tr>";
    for (var i = 0; i < groupDataList.length; i++) {
        var groupData = groupDataList[i];
        var test = "";
        for (var j = 0; j < size; j++) {
            var da = groupData.arr[j];
            test += da;

        }
        if (size == 2 && (test == "闲闲")) {
            stringBufferLine += "<td>×</td>";
        } else if (size == 2 && (test == "庄庄")) {
            stringBufferLine += "<td>×</td>";
        } else if (size == 3 && diff && (test == "闲闲闲" || test == "庄庄庄")) {
            stringBufferLine += "<td>×</td>";
        } else if (size == 3 && same && (test == "闲庄庄" || test == "庄闲闲")) {
            stringBufferLine += "<td>×</td>";
        } else {
            stringBufferLine += "<td>=</td>";
        }
    }
    stringBufferLine += "</tr>";
    return stringBufferLine;

}